﻿@using Microsoft.AspNetCore.Mvc.Localization
@using Skoruba.IdentityServer4.Admin.BusinessLogic.Shared.Dtos.Common
@model Skoruba.IdentityServer4.Admin.BusinessLogic.Dtos.Configuration.ApiScopesDto
@inject IViewLocalizer Localizer

@{
	ViewBag.Title = Localizer["PageTitle"];
	Layout = "_Layout";
}

<div class="row">
	<div class="col-12">
		<nav aria-label="breadcrumb">
			<ol class="breadcrumb">
				<li class="breadcrumb-item"><a asp-controller="Configuration" asp-action="ApiResources">@Localizer["NavigationApiResources"]</a></li>
				<li class="breadcrumb-item"><a asp-controller="Configuration" asp-action="ApiResource" asp-route-id="@Model.ApiResourceId">@Model.ResourceName</a></li>

				@if (Model.ApiScopeId != 0)
				{
					<li class="breadcrumb-item"><a asp-controller="Configuration" asp-action="ApiScopes" asp-route-id="@Model.ApiResourceId">@Localizer["NavigationApiScopes"]</a></li>
					<li class="breadcrumb-item active" aria-current="page">@Model.Name</li>
				}
				else
				{
					<li class="breadcrumb-item active" aria-current="page">@Localizer["NavigationApiScopes"]</li>
				}
			</ol>
		</nav>
	</div>

	<div class="col-12">
		<h2>@Localizer["PageTitle"]</h2>
	</div>
</div>

<form asp-action="ApiScopes" asp-route-scope="@Model.ApiScopeId" id="api-scope-form" method="post">

	<div asp-validation-summary="All" class="text-danger"></div>

	<!--Hidden -->
	<input type="hidden" asp-for="ApiScopeId" />

	<!--Hidden -->
	<input type="hidden" asp-for="ApiResourceId" />

	<div class="card mt-3">
		<h5 class="card-header">@Localizer["PanelTitle"]</h5>
		<div class="card-body">
			<!--Input - text -->
			<div class="form-group row">
				<label asp-for="Name" class="col-sm-3 col-form-label">
					@await Html.PartialAsync("ApiResource/Section/Label", "Name")
				</label>
				<div class="col-sm-9">
					<input type="text" required class="form-control" asp-for="Name">
					<span asp-validation-for="Name" class="text-danger"></span>
				</div>
			</div>

			<!--Input - text -->
			<div class="form-group row">
				<label asp-for="DisplayName" class="col-sm-3 col-form-label">
					@await Html.PartialAsync("ApiResource/Section/Label", "DisplayName")
				</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" asp-for="DisplayName">
				</div>
			</div>

			<!--Input - text -->
			<div class="form-group row">
				<label asp-for="Description" class="col-sm-3 col-form-label">
					@await Html.PartialAsync("ApiResource/Section/Label", "Description")
				</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" asp-for="Description">
				</div>
			</div>

			<!--Checkbox-->
			<div class="form-group row">
				<label asp-for="Required" class="col-sm-3 col-form-label">
					@await Html.PartialAsync("IdentityResource/Section/Label", "Required")
				</label>
				<div class="col-sm-9">
					<toggle-button>
						<input asp-for="Required" type="checkbox">
					</toggle-button>
				</div>
			</div>

			<!--Checkbox-->
			<div class="form-group row">
				<label asp-for="Emphasize" class="col-sm-3 col-form-label">
					@await Html.PartialAsync("IdentityResource/Section/Label", "Emphasize")
				</label>
				<div class="col-sm-9">
					<toggle-button>
						<input asp-for="Emphasize" type="checkbox">
					</toggle-button>
				</div>
			</div>

			<!--Select with tags-->
			<div class="form-group row">
				<label asp-for="UserClaims" class="col-sm-3 col-form-label">
					@await Html.PartialAsync("ApiResource/Section/Label", "UserClaims")
				</label>
				<div class="col-sm-9">
					<picker id="UserClaimsItems" multiple-select="true" min-search-text="2"
							selected-items="@Model.UserClaims" url="@Url.Action("SearchClaims","Configuration")?claim"
					        search-input-placeholder="@Localizer["PickerSearchItemPlaceholder"].Value"
					        selected-items-title="@Localizer["PickerSelectedItemsTitle"].Value" 
					        search-result-title="@Localizer["PickerSearchResultTitle"].Value"
					        suggested-items-title="@Localizer["PickerSuggestedItemsTitle"].Value" 
					        no-item-selected-title="@Localizer["PickerNoItemSelectedTitle"].Value" 
					        show-all-items-title="@Localizer["PickerShowAllItemsTitle"].Value"
					        item-already-selected-title="@Localizer["PickerItemAlreadySelectedTitle"].Value">
					</picker>
				</div>
			</div>

			<!--Button-->
			<div class="form-group row">
				<label class="col-sm-3 col-form-label">
				</label>
				<div class="col-sm-9">
					<button type="submit" asp-action="ApiScopes" id="api-scope-save-button" class="btn btn-primary">@Localizer["ButtonAddApiScope"]</button>
				</div>
			</div>
		</div>
	</div>

</form>

@if (Model.ApiScopeId == 0)
{
	<div class="row">
		<div class="col-md-12">
			<div class="card mt-3">
				<h5 class="card-header">@Localizer["PageTitle"]</h5>
				<div class="card-body">
					<div class="row table-responsive">
						<table class="table table-striped">
							<thead>
								<tr>
									<th>@Localizer["TableName"]</th>
									<th></th>
								</tr>
							</thead>

							<tbody>
								@foreach (var scope in Model.Scopes)
								{
									<tr>
										<td>@scope.Name</td>
										<td><a asp-action="ApiScopes" asp-route-scope="@scope.Id" class="btn btn-primary">@Localizer["TableButtonEdit"]</a> <a asp-action="ApiScopeDelete" asp-route-id="@Model.ApiResourceId" asp-route-scope="@scope.Id" class="btn btn-danger">@Localizer["TableButtonRemove"]</a></td>
									</tr>
								}
							</tbody>
						</table>
					</div>

					<div class="row">
						<div class="col-12">
							@await Html.PartialAsync("Common/Pager", new Pager() { Action = "ApiScopes", PageSize = Model.PageSize, TotalCount = Model.TotalCount })
						</div>
					</div>

				</div>
			</div>

		</div>
	</div>
}

@section scripts
	{
	<script>
		$(function () {
			//Disable enter for this form
			FormMvc.disableEnter($('#api-scope-form'));
		});
	</script>
}